#define   osObjectsPublic                                       // define objects in rtxapp module
#include "osObjects.h"                                          // RTOS object definitions

/*----------------------------------------------------------------------------
 *     
 *---------------------------------------------------------------------------*/
 
/*
*********************************************************************************************************
*                                          AppTaskCreate()
*
* Description : Create application tasks.
*
* Argument(s) : none
*
* Return(s)   : none
*
* Caller(s)   : AppTaskStart()
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  AppTaskCreate (void)
{
    OS_ERR  err;
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&LedCtrTaskTCB,            
                 (CPU_CHAR    *)"LED Task",
                 (OS_TASK_PTR  )LedCtrTask,
                 (void        *)0u,
                 (OS_PRIO      )TASK_LEDCTR_PRIO,
                 (CPU_STK     *)&LedCtrTaskStk[0],
                 (CPU_STK_SIZE )TASK_LEDCTR_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_LEDCTR_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err);
   
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&StorageTaskTCB,            
                 (CPU_CHAR    *)"Storage Task",
                 (OS_TASK_PTR  )StorageTask,
                 (void        *)0u,
                 (OS_PRIO      )TASK_STORAGE_PRIO,
                 (CPU_STK     *)&StorageTaskStk[0],
                 (CPU_STK_SIZE )TASK_STORAGE_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_STORAGE_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err); 
    
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&LcdCtrTaskTCB,            
                 (CPU_CHAR    *)"LCD Task",
                 (OS_TASK_PTR  )LcdCtrTask,
                 (void        *)0u,
                 (OS_PRIO      )TASK_LCDCTR_PRIO,
                 (CPU_STK     *)&LcdCtrTaskStk[0],
                 (CPU_STK_SIZE )TASK_LCDCTR_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_LCDCTR_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err); 
    
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&TestTaskTCB,             
                 (CPU_CHAR    *)"TEST Task",
                 (OS_TASK_PTR  )TestTask,
                 (void        *)0u,
                 (OS_PRIO      )TASK_TEST_PRIO,
                 (CPU_STK     *)&TestTaskStk[0],
                 (CPU_STK_SIZE )TASK_TEST_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_TEST_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err); 
    
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&SysTaskTCB,             
                 (CPU_CHAR    *)"SYS Task",
                 (OS_TASK_PTR  )SysTask,
                 (void        *)0u,
                 (OS_PRIO      )TASK_SYS_PRIO,
                 (CPU_STK     *)&SysTaskStk[0],
                 (CPU_STK_SIZE )TASK_SYS_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_SYS_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err); 
    
    //-----------------------------------------------------------------------------------------------------------------------------
    OSTaskCreate((OS_TCB      *)&ModbusTaskTCB,             
                 (CPU_CHAR    *)"MODBUS Task",
                 (OS_TASK_PTR  )ModbusTask,
                 (void        *)0u,
                 (OS_PRIO      )TASK_MODBUS_PRIO,
                 (CPU_STK     *)&ModbusTaskStk[0],
                 (CPU_STK_SIZE )TASK_MODBUS_STK_SIZE*10/100,
                 (CPU_STK_SIZE )TASK_MODBUS_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0u,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&err);  
				                 
}


/*
*********************************************************************************************************
*                                          AppTaskBlinky()
*
* Description : Simple task that blinks the user LEDs at a faster rate than Startup Task if Push Button
*               is pressed.
*
* Argument(s) : none
*
* Return(s)   : none
*
* Caller(s)   : AppTaskCreate()
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  AppTaskBlinky (void *p_arg)
{
    OS_ERR      os_err;

    (void)p_arg;
    
    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.       */

 
            OSTimeDlyHMSM(0u, 0u, 0u, 10u,
                          OS_OPT_TIME_HMSM_STRICT,
                          &os_err);
    }
}


/*
*********************************************************************************************************
*                                          AppObjCreate()
*
* Description : Create application kernel objects tasks.
*
* Argument(s) : none
*
* Return(s)   : none
*
* Caller(s)   : AppTaskStart()
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  AppObjCreate (void)
{
    OS_ERR      os_err;
    
    //-----------------------------------------------------------------------------------------------------------------------------
    OSMutexCreate (&MutexObjI2C, "MUTEX_IIC", &os_err);
    OSMutexCreate (&MutexObjLcd, "MUTEX_IIC", &os_err);
}


